package com.lyc.servlet.admin;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.lyc.R;
import com.lyc.dao.MedalInfoDAO;
import com.lyc.dao.imp.MedalInfoDAOImpl;
import com.lyc.dto.MedalSearch;
import com.lyc.entity.MedalInfo;
import com.lyc.service.MedalService;
import com.lyc.service.impl.MedalServiceImpl;

@WebServlet("/admin/medal-page.let")
public class MedalInfoPageServlet extends HttpServlet {
	private MedalService service = new MedalServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		MedalSearch search = new MedalSearch();
		try {
			search.setCurrent(Integer.valueOf(request.getParameter("current")));
		}catch(Exception e) {}
		
		try {
			search.setRowMax(Integer.valueOf(request.getParameter("rowMax")));
		}catch(Exception e) {}
		
		try {
			search.setSeId(Integer.valueOf(request.getParameter("seId")));
		}catch(Exception e) {}
		
		search.setKey(request.getParameter("key"));
		
		response.reset();
		response.setContentType("application/json;charset=utf-8");
		
		try {
//			List<MedalInfo> list = dao.select(0, 999);
			response.getWriter().print(JSON.toJSONString(service.page(search)));
		} catch (Exception e) {
			response.getWriter().print(JSON.toJSONString(R.error().setMessage(e.getMessage())));
			e.printStackTrace();
		}
		response.flushBuffer();
	}

}
